import { onMounted } from "vue";
import { registerMicroApps, start } from "qiankun";
import { childrenList } from "@/constant/dictionary";

export function useLoadChild() {
  onMounted(() => {
    if (!childrenList.length) {
      return;
    }
    registerMicroApps(childrenList, {
      beforeLoad: [
        function (app) {
          console.log("[主应用] before mount %c%s", "color: green;", app.name);
        },
      ],
      beforeMount: [
        function (app) {
          console.log("[主应用] before mount %c%s", "color: green;", app.name);
        },
      ],
      afterMount: [
        function (app) {
          console.log(
            "[主应用] afterMount mount %c%s",
            "color: green;",
            app.name
          );
        },
      ],
      afterUnmount: [
        function (app) {
          console.log("[主应用] after unmount %c%s", "color: green;", app.name);
        },
      ],
    });
    // delete window.Vue;
    start({
      // prefetch: "all", //预加载
      // singular: false,
      sandbox: false,
    });
  });
}
